import { defineStore } from 'pinia'
import { getReportListApi } from '@/apis/user'
import { useLangStore } from './lang'

const langStore = useLangStore()

function isPC() {
  var userAgentInfo = navigator.userAgent
  var Agents = new Array('Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod')
  var flag = true
  for (var v = 0; v < Agents.length; v++) {
    if (userAgentInfo.indexOf(Agents[v]) > 0) {
      flag = false
      break
    }
  }
  return flag
}

export const useUserStore = defineStore('user', {
  state: () => {
    return {
      isPC: isPC(),
      watermarkcontent: '',
      watermarkshow: false
    }
  },
  actions: {
    // 设置水印
    setWaterMark(content, show) {
      if (content) {
        this.watermarkcontent = content
      }
      this.watermarkshow = show
    },
    // 获取公司名称
    async getCompanyName() {
      const res = await getReportListApi()
      if (res.data.code == 200) {
        let lang = langStore.getLang
        lang === 'en'
          ? (this.watermarkcontent = `only ${res.data.data.customername} use`)
          : (this.watermarkcontent = `仅限${res.data.data.customername}使用`)
      }
    }
  }
})
